package by.blog.service;

import by.blog.dao.beans.Category;
import by.blog.dao.beans.Film;
import by.blog.dao.dao.DaoFilm;

import java.util.List;

/**
 * Бондарчик Антон  15.11.2014.
 */
public class FilmService implements ServiceInterface<Film, Integer> {
    private DaoFilm daoFilm;
    private CategoryService categoryService;

    private List<Film> listOfAllFilms;

    public FilmService() {
        daoFilm = new DaoFilm();

    }

    public boolean createUnit(Film film) {
        boolean state = daoFilm.createUnit(film);
        //listOfAllFilms = daoFilm.readAllUnits();
        return state;
    }

    public Film readUnit(Integer INDEX) {
        return daoFilm.readUnit(INDEX);
    }

    public boolean updateUnit(Film film) {
        boolean state = daoFilm.updateUnit(film);
        //listOfAllFilms = daoFilm.readAllUnits();
        return state;
    }

    public boolean deleteUnit(Integer INDEX) {
        boolean state = daoFilm.deleteUnit(INDEX);
        //listOfAllFilms = daoFilm.readAllUnits();
        return state;
    }

    public List<Film> readUnitsByParent(String categoryName) {
        categoryService = new CategoryService();
        List<Category> categoryList = categoryService.getListOfAllCategories();

        int id=0;
        for (Category category:categoryList) {
            if (category.getCategory_name() == categoryName) {
                id =category.getCategory_id();
                break;
            }
        }
        return daoFilm.readUnitsByParent(id);
    }

    public List<Film> readUnitsByParent(int INDEX) {
        return daoFilm.readUnitsByParent(INDEX);
    }

    public List<Film> readAllUnits() {
        return daoFilm.readAllUnits();
    }

    public List<Film> getListOfAllFilms() {
        return listOfAllFilms;
    }

    public void setListOfAllFilms(List<Film> listOfAllFilms) {
        this.listOfAllFilms = listOfAllFilms;
    }
}
